home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Include / FWGrObj.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  4.5 KB  |  158 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrObj.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWGROBJ_H
  13. #define FWGROBJ_H
  14.  
  15. #ifndef FWSTREAM_H
  16. #include "FWStream.h"
  17. #endif
  18.  
  19. // ----- Foundation Includes -----
  20.  
  21. #ifndef FWSTDDEF_H
  22. #include <FWStdDef.h>
  23. #endif
  24.  
  25. //==============================================================================
  26. //    •• class FW_CGraphicObjectRep
  27. //==============================================================================
  28.  
  29. class FW_CGraphicObjectRep
  30. {
  31.     friend class FW_CGraphicObjectPtr;
  32.     
  33. //------------------------------------------------------------------------------
  34. //    • Constructors/Destructors
  35. //
  36.     friend class FW_CGraphicObjectPtr;
  37.     
  38. protected:
  39.     FW_CGraphicObjectRep();
  40.     virtual ~FW_CGraphicObjectRep();
  41.  
  42. //------------------------------------------------------------------------------
  43. //    • New API
  44. //
  45. public:
  46.     unsigned long            GetSeed() const
  47.                                 {return fSeed;}
  48.                             
  49.     unsigned long            GetRefCount() const
  50.                                 {return fRefCount;}
  51.  
  52.     virtual void            Flatten(FW_CWritableStream& stream) = 0;
  53.     virtual void            Unflatten(FW_CReadableStream& stream) = 0;
  54.     
  55. protected:
  56.     void                    Changed();
  57.  
  58.     void                    IncrementRefCount()
  59.                                 {fRefCount++;}
  60.     unsigned long            Release()
  61.                                 {return --fRefCount;}
  62.                             
  63. //------------------------------------------------------------------------------
  64. //    • Data Members
  65. //
  66. private:
  67.     unsigned long            fSeed;
  68.     unsigned long            fRefCount;
  69. };
  70.  
  71. //========================================================================================
  72. //    •• CLASS FW_CGraphicObjectPtr
  73. //========================================================================================
  74.  
  75. class FW_CGraphicObjectPtr
  76. {
  77. public:
  78.     FW_CGraphicObjectPtr();
  79.         // Creates a "NULL" pointer.
  80.  
  81.     FW_CGraphicObjectPtr(const FW_CGraphicObjectPtr& other);
  82.         // FW_SPlatformPoint this pointer to the same rep as the other pointer points to.
  83.  
  84.     FW_CGraphicObjectPtr(FW_CGraphicObjectRep* rep);
  85.         // Creates a pointer pointing at rep.
  86.  
  87.     ~FW_CGraphicObjectPtr();
  88.         // Destroy the pointer.  
  89.         // Decrements the count in the rep, and deletes the rep if count is zero.
  90.  
  91. /*            
  92.     FW_CGraphicObjectPtr& operator=(const FW_CGraphicObjectPtr& other);
  93.         // Assignment, point this pointer to the same rep as the other pointer points to.
  94.         
  95.     FW_CGraphicObjectPtr& operator=(FW_CGraphicObjectRep* rep);
  96.         // Assignment, point this ponter to rep.
  97.         
  98.     FW_CGraphicObjectRep* operator->() const;
  99.         // Provide access to members of rep.
  100.         
  101.     FW_CGraphicObjectRep& operator*() const;
  102.         // Provide access to rep.
  103.         // This operator should be used only if operator->() is not sufficient.
  104. */
  105.  
  106.     FW_Boolean operator==(const FW_CGraphicObjectPtr& other) const;
  107.         // Points to the same representation object?
  108.  
  109.     FW_Boolean operator!=(const FW_CGraphicObjectPtr& other) const;
  110.         // Points to a different representation object?
  111.  
  112.     operator const void*() const;
  113.         // Use to test if this is a "NULL" pointer.
  114.  
  115. protected:    
  116.     void UpCount();
  117.         // Implementation method, increment the reference count in rep.
  118.         
  119.     void DownCount();
  120.         // Implementation method, decrement the reference count in rep.
  121.         // Deletes rep if reference count is zero.
  122.     
  123.     FW_CGraphicObjectRep*     GetRep() const
  124.                                 {return fRep;}
  125.     void                    SetRep(FW_CGraphicObjectRep* rep);
  126.     
  127. private:    
  128.     FW_CGraphicObjectRep *fRep;
  129. };
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // FW_CGraphicObjectPtr::operator==
  133. //----------------------------------------------------------------------------------------
  134.  
  135. inline FW_Boolean FW_CGraphicObjectPtr::operator==(const FW_CGraphicObjectPtr& other) const
  136. {
  137.     return (fRep == other.fRep);
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // FW_CGraphicObjectPtr::operator!=
  142. //----------------------------------------------------------------------------------------
  143.  
  144. inline FW_Boolean FW_CGraphicObjectPtr::operator!=(const FW_CGraphicObjectPtr& other) const
  145. {
  146.     return !operator==(other);
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // FW_CGraphicObjectPtr::operator const void*
  151. //----------------------------------------------------------------------------------------
  152.  
  153. inline FW_CGraphicObjectPtr::operator const void*() const
  154. {
  155.     return (const void*) fRep;
  156. }
  157.  
  158. #endif